package com.woniuxy.service.impl;

import com.woniuxy.entity.dto.BindManAndOrderDTO;
import com.woniuxy.entity.dto.DeliveryOrderQueryDTO;
import com.woniuxy.mapper.DeliveryOrderMapper;
import com.woniuxy.service.DeliveryOrderService;
import com.woniuxy.util.ResponseData;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @BelongsProject: pigTrotterStore
 * @BelongsPackage: com.woniuxy.service
 * @Author: Quan
 * @Date: 2025/3/18 20:04
 */
@Service
@AllArgsConstructor
public class DeliveryOrderServiceImpl implements DeliveryOrderService {
	private DeliveryOrderMapper orderMapper;
	
	/** 
	 * @Description: 按照条件查询订单信息
	 * @Param: [orderQueryDTO]
	 * @return: com.woniuxy.util.ResponseData<?>
	 * @Author: Quan
	 * @Date: 2025/3/18
	 */
	@Override
	public ResponseData<?> queryInfo(DeliveryOrderQueryDTO orderQueryDTO) {
		String[] split = orderQueryDTO.getOrderTime().split("-");
		String type = split[0];
		String num = split.length == 1 ? "" : split[1];
		orderQueryDTO.setType(type);
		orderQueryDTO.setNum(split.length == 1 ? null : Integer.valueOf(split[1]));
		return ResponseData.ok(orderMapper.queryInfo(orderQueryDTO));
	}

	/**
	 * @Description: 绑定外卖员与订单
	 * @Param: [manAndOrderDTO]
	 * @return: com.woniuxy.util.ResponseData<?>
	 * @Author: Quan
	 * @Date: 2025/3/18
	 * @todo:没有考虑线程安全
	 * 1、将外卖员与订单的信息添加到order_bind_takeaway_man表中
	 * 2、修改订单对应id的状态
	 * 3、添加外卖员持有的外卖数
	 */
	@Override
	public ResponseData<?> bindManAndOrder(BindManAndOrderDTO manAndOrderDTO) {
		// 将外卖员与订单编号添加到新表中
		orderMapper.addOrderAndManToBindTable(manAndOrderDTO);
		// 修改订单对应的id状态
		orderMapper.changeOrderState(manAndOrderDTO.getOrderId(), 2);
		// 添加外卖员持有的外卖数
		//待定？？？
		return ResponseData.ok();
	}
}
